from PySide6.QtCore import QRect


def get_taskbar_rect():
    import ctypes
    from ctypes import wintypes

    # 加载 C 语言编译好的 DLL 库
    libwin = ctypes.cdll.LoadLibrary('cmake/lib/libwin.dll')

    # 定义 GetTaskbarRect 函数的返回值类型和参数类型
    libwin.GetTaskbarRect.restype = None
    libwin.GetTaskbarRect.argtypes = [ctypes.POINTER(wintypes.RECT)]

    # 调用 GetTaskbarRect 函数获取任务栏信息
    rect = wintypes.RECT()
    libwin.GetTaskbarRect(ctypes.byref(rect))

    # 考虑屏幕缩放
    libwin.GetScreenScale.restype = ctypes.c_double
    libwin.GetScreenScale.argtypes = None

    scale = libwin.GetScreenScale()
    x, y = int(rect.left / scale), int(rect.top / scale)
    w, h = int((rect.right - rect.left) / scale), int((rect.bottom - rect.top) / scale)

    return QRect(x, y, w, h)


def is_theme_light():
    import winreg

    key_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize'
    value_name = 'AppsUseLightTheme'

    try:
        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path)
        value, _ = winreg.QueryValueEx(key, value_name)
        return value  # 0：暗主题，1：亮主题
    except Exception as e:
        print(e)
        return None  # 无法确定主题
